package com.waitingresult.collection.list;


import com.waitingresult.entity.User;

import java.util.ArrayList;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @Author: WangShuai
 * @CreateTime: 2022-10-16  18:22
 * @Description: list 转Map
 * @Version: 1.0
 */
public class List2Map {
    public static void main(String[] args) {
        ArrayList<User> users = initUsers();
        Map<Long, User> collect = users.stream().collect(Collectors.toMap(User::getId, Function.identity()));
        System.err.println(collect);
    }

    private static ArrayList<User> initUsers() {
        ArrayList<User> users = new ArrayList<User>();
        for (long i = 0; i < 10; i++) {
            users.add(new User(i,"张三"+i,"安徽"));
        }
        return users;
    }
}
